package com.guava.baseutils;

import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Ordering;

/**
 * @author: sun.hongliang
 * @create: 2019/03/20 12:28
 */
public class Person implements Comparable<Person> {

    private String lastName;
    private String firstName;
    private int zipCode;

    public Person(String lastName, String firstName, int zipCode) {
        this.lastName = lastName;
        this.firstName = firstName;
        this.zipCode = zipCode;
    }

    @Override
    public int compareTo(Person that) {
        int result = ComparisonChain.start().
                compare(this.lastName, that.lastName, Ordering.natural().nullsLast()).
                compare(this.zipCode, that.zipCode).result();
        return result;
    }

    @Override
    public String toString() {
        return "Person{" +
                "lastName='" + lastName + '\'' +
                ", firstName='" + firstName + '\'' +
                ", zipCode=" + zipCode +
                '}';
    }
}
